<template xmlns="http://www.w3.org/1999/html">
  <sea-data-table ref="tableObject" url="/sys/msg/page" :on-action="onAction">
    <!--表头-->
    <sea-table-header slot="header">
      <!--标题栏-->
      <sea-table-title slot="title" title="消息模版" subtitle="向上可以扩展出：短信、邮件、系统通知等模块，提供了基础的验证功能。"></sea-table-title>

      <!--按钮栏-->
      <template slot="buttons">
        <el-button plain size="small" title="新增" icon="fa fa-plus" @click="onAction('new')"></el-button>
      </template>
    </sea-table-header>

    <!--表头-->
    <template slot="columns">
      <el-table-column property="name" label="名称" width="180"></el-table-column>
      <el-table-column property="description" label="描述"></el-table-column>
      <sea-col-text property="disabled" label="是否可用" width="180"></sea-col-text>
      <el-table-column property="gmtCreate" label="创建日期" width="180"></el-table-column>
      <el-table-column property="gmtModified" label="修改日期" width="180"></el-table-column>

      <!--操作栏-->
      <sea-table-actionbar width="180" :on-action="onAction" :buttons="buttons"></sea-table-actionbar>
    </template>

    <!-- 弹窗、抽屉 -->
    <template slot="drawer">
      <sea-dialog ref="create_dialog">
        <el-row>
          <el-col class="sea-card">
            <modify ref="modify" :guid="row_id"></modify>
          </el-col>
          <el-col class="sea-card">
            <props-detail :guid="row_id"></props-detail>
          </el-col>
        </el-row>
      </sea-dialog>
      <sea-dialog ref="modify_props_dialog">
        <el-col class="sea-card">
          <props-modify :guid="row_id"></props-modify>
        </el-col>
      </sea-dialog>
    </template>
<!--      <panel ref="panel"></panel>-->
  </sea-data-table>
</template>

<script>
import modify from "./modify";
import PropsDetail from "./props/detail";
import PropsModify from "./props/modify";

export default {
    components: {modify, PropsDetail, PropsModify},
    data() {
        return {
            // 操作名称
            operation: undefined
            // 当前操作的行级对象
            , row_data: undefined
            // 数据ID
            , row_id: undefined
            // 操作栏
            , buttons: [
                {evt: 'tpl', type: 'btn', label: '模版', title: '编辑消息模版'}
                , {evt: 'props', type: 'btn', label: '参数', title: '编辑消息参数'}
                , {evt: 'remove', type: 'btn', label: '删除', style: 'text-danger', title: '删除当前行'}
            ]
            // end--
        }
    },
    methods: {
        /**
         * 操作成功回调
         */
        onSucceed: function () {
            this.$refs.tableObject.reload();
        },
        /**
         * 操作栏事件分发
         * @param evt 事件
         * @param row 行级对象
         * @param old 可供回滚的参数
         */
        onAction: function (evt, row, old) {
            this.operation = evt;
            if (evt === 'tpl') {
                let dialog = {title: `模版 - ${row.name}`, width: '50%'};
                this.$refs.create_dialog.open(dialog).then(() => {
                    this.row_id = row.id;
                });
            } else if (evt === 'props') {
                let dialog = {title: `参数 - ${row.name}`, width: '70%'};
                this.$refs.modify_props_dialog.open(dialog).then(() => {
                    this.row_id = row.id;
                });
            // } else if (evt === 'new') {
            //     let dialog = {title: `新建`, width: '50%'};
            //     this.$refs.create_dialog.open(dialog).then(() => {
            //     });
            }
            // this.$refs.panel.onAction(evt, row, old);
        }
    }
}
</script>
